package com.zh.note.demo.javaSE;

import java.util.*;

public class ScannerDemo {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = Integer.parseInt(in.nextLine());
            //为什么不用int n = in.nextInt();?有兴趣的读者可以自行尝试，看看会出什么问题
            for (int i = 0; i < n; ++i) {
                String str = in.nextLine();
                char[] chs = str.toCharArray();
                Map<Character, Integer> map = new HashMap<>();
                for (char c : chs) {
                    if (map.get(c) == null) map.put(c, 1);
                    else map.put(c, map.get(c) + 1);
                }
                List<Map.Entry<Character, Integer>> list = new ArrayList<>(map.entrySet());
                Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() {
                    public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
                        return o2.getValue() - o1.getValue();
                    }
                });
                int res = 0;
                int value = 26;
                for (Map.Entry<Character, Integer> entry : list) {
                    res += value-- * entry.getValue();
                }
                System.out.println(res);
            }
        }

    }
}

